import {
  querySummaryReq, queryChildrenReq, queryLogReq, queryRestartReq, queryStopReq, queryGetAllTaskFlowReq,
  queryGetCallUserInfoReq, querySaveReq, queryGetParentTypeReq, queryTodayReq, queryTaskMonitorListReq,
  queryUserListReq, queryChangeReq, queryJobChildrenReq, ignore,
} from './api'

export default {
  namespace: 'offlineOperation',
  state: {},
  effects: {
    * querySummary({ params, cb }, { call, put }) {
      const res = yield call(querySummaryReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryChildren({ params, cb }, { call, put }) {
      const res = yield call(queryChildrenReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryLog({ params, cb }, { call, put }) {
      const res = yield call(queryLogReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryRestart({ params, cb }, { call, put }) {
      const res = yield call(queryRestartReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryStop({ params, cb }, { call, put }) {
      const res = yield call(queryStopReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryGetAllTaskFlow({ params, cb }, { call, put }) {
      const res = yield call(queryGetAllTaskFlowReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryGetCallUserInfo({ params, cb }, { call, put }) {
      const res = yield call(queryGetCallUserInfoReq, params)
      if (cb) {
        cb(res)
      }
    },
    * querySave({ params, cb }, { call, put }) {
      const res = yield call(querySaveReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryGetParentType({ params, cb }, { call, put }) {
      const res = yield call(queryGetParentTypeReq, params)
      if (cb) {
        cb(res)
      }
    },
    * saveTableQuery({ params, cb }, { put }) {
      yield put({ type: 'save', payload: params })
    },
    * saveFilterValue({ params, cb }, { put }) {
      yield put({ type: 'save', payload: params })
    },
    * clearFilterValue({ params, cb }, { put }) {
      yield put({ type: 'save', payload: params })
    },
    * saveSearchDefault({ params, cb }, { put }) {
      yield put({ type: 'save', payload: params })
    },
    * queryToday({ params, cb }, { call, put }) {
      const res = yield call(queryTodayReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryTaskMonitorList({ params, cb }, { call, put }) {
      const res = yield call(queryTaskMonitorListReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryUserList({ params, cb }, { call, put }) {
      const res = yield call(queryUserListReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryChange({ params, cb }, { call, put }) {
      const res = yield call(queryChangeReq, params)
      if (cb) {
        cb(res)
      }
    },
    //
    * queryJobChildren({ params, cb }, { call, put }) {
      const res = yield call(queryJobChildrenReq, params)
      if (cb) {
        cb(res)
      }
    },
    * saveLinkInfo({ params, cb }, { put }) {
      yield put({ type: 'save', payload: params })
    },
    * queryIgnore({ params, cb }, { call, put }) {
      const res = yield call(ignore, params)
      if (cb) {
        cb(res)
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      }
    },
  },
}
